package com.youlu.campus.web.client;

import lombok.extern.slf4j.Slf4j;

import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class QQFallbackFactory  implements FallbackFactory<QQTokenClient> {
    @Override
    public QQTokenClient create(Throwable cause) {
        return new QQTokenClient() {
            QQResult qqResult = new QQResult();

//            @Override
//            public QQResult getAccessToken(String grantType, String clientId, String clientSecret, String code,
//                                           String redirectUri,String scope, String fmt) {
//                log.error("【QQ-H5-ACCESS-TOKEN】获取access_token error appId - {}",clientId,cause);
//                qqResult.setCode(500);
//                return qqResult;
//            }

            @Override
            public QQResult getRenewalAccessToken(String grantType, String clientId, String clientSecret, String fmt) {
                log.error("【QQ-H5-ACCESS-TOKEN】 refresh_token error appId - {}",clientId,cause);
                qqResult.setCode(500);
                return qqResult;
            }

            @Override
            public QQResult getOpenId(String accessToken, String fmt) {
                log.error("【QQ-H5-OPEN-ID】 openid error accessToken - {}",accessToken,cause);
                qqResult.setCode(500);
                return qqResult;
            }

            @Override
            public QQUserInfoResult getUserInfo(String accessToken, String oauthConsumerKey, String openId, String fmt) {
                QQUserInfoResult qqUserInfoResult = new QQUserInfoResult();
                log.error("【QQ-H5-USER-INFO】 user-info error oauthConsumerKey - >{} openid - {}",oauthConsumerKey, openId,cause);
                qqUserInfoResult.setRet(500);
                return qqUserInfoResult;
            }
        };
    }
}
